package com.ruoyi.standingbook.sanitationvehicle.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.standingbook.sanitationvehicle.domain.bo.SanitationVehicleBo;
import com.ruoyi.standingbook.sanitationvehicle.domain.vo.SanitationVehiclePicVo;
import com.ruoyi.standingbook.sanitationvehicle.domain.vo.SanitationVehicleVo;
import com.ruoyi.standingbook.sanitationvehicle.service.ISanitationVehicleService;

import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 
 * 环卫作业车任务完成进度
 *
 * @author lq
 * @date 2024-01-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/standingbook/sanitationVehicle")
public class SanitationVehicleController extends BaseController {

	private final ISanitationVehicleService sanitationVehicleService;

	/**
	 * 查询环卫作业车任务完成进度列表
	 */
	@SaCheckPermission("standingbook:sanitationVehicle:list")
	@GetMapping("/list")
	public TableDataInfo<SanitationVehicleVo> list(SanitationVehicleBo bo, PageQuery pageQuery) {
		return sanitationVehicleService.queryPageList(bo, pageQuery);
	}

	/**
	 * 导出环卫作业车任务完成进度列表
	 */
	@SaCheckPermission("standingbook:sanitationVehicle:export")
	@Log(title = "环卫作业车任务完成进度", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(SanitationVehicleBo bo, HttpServletResponse response) {
		List<SanitationVehicleVo> list = sanitationVehicleService.queryList(bo);
		ExcelUtil.exportExcel(list, "环卫作业车任务完成进度", SanitationVehicleVo.class, response);
	}

	/**
	 * 获取环卫作业车任务完成进度详细信息
	 *
	 * @param id 主键
	 */
	@SaCheckPermission("standingbook:sanitationVehicle:query")
	@GetMapping("/{id}")
	public R<SanitationVehicleVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable String id) {
		return R.ok(sanitationVehicleService.queryById(id));
	}

	/**
	 * 删除环卫作业车任务完成进度
	 *
	 * @param ids 主键串
	 */
	@SaCheckPermission("standingbook:sanitationVehicle:remove")
	@Log(title = "环卫作业车任务完成进度", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] ids) {
		return toAjax(sanitationVehicleService.deleteWithValidByIds(Arrays.asList(ids), true));
	}

	@GetMapping("/sanitationVehiclePic")
	public R<List<SanitationVehiclePicVo>> SanitationVehiclePic(String date) {
		return R.ok(sanitationVehicleService.getSanitationVehiclePicByDate(date));
	}
}
